/**
 * There are code generation
 */
package com.neusoft.lohas.modules.ivm.dao.purchase;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.neusoft.lohas.common.persistence.BaseDao;
import com.neusoft.lohas.common.persistence.Parameter;
import com.neusoft.lohas.modules.ivm.entity.purchase.Purchase;

/**
 * 采购指令DAO接口
 * @author Jackie.Liu
 * @version 2014-12-29
 */
@Repository
public class PurchaseDao extends BaseDao<Purchase> {
	public int getOrderNumsByDate(String merchantId){
		String sql = "select count(*) from ivm_purchase where date(create_date) = date(now()) and del_flag=0 and merchant_id='"+merchantId+"'";
		List<Object> list = findBySql(sql, new Parameter());
		int len = 0;
		if(list == null || list.get(0).toString().equals("0")){
			len = 0;
		}else{
			sql = "select max(code) from ivm_purchase where date(create_date) = date(now()) and del_flag=0 and merchant_id='"+merchantId+"'";
			list = findBySql(sql, new Parameter());
			String code = list.get(0).toString();
			code = code.substring(code.length()-3);
			len = Integer.valueOf(code);
		}
		return len;
	}
}
